package com.tengju.data.domain.shared;

import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

@Getter
public class Year {
    private LocalDate yearStartDate;
    private LocalDate yearEndDate;
    private Integer yearStartMonthInt;
    private Integer yearEndMonthInt;

    public Year(String year) {
        if (StringUtils.isBlank(year)) {
            return;
        }
        LocalDate yearStartDate = LocalDate.parse(year + "01" + "01", DateTimeFormatter.ofPattern(DateUtil.DATE_FORMAT));
        Integer yearStartMonth = new Month(yearStartDate).getMonthInt();
        Integer yearEndMonth = new Month(yearStartDate.withMonth(12)).getMonthInt();
        this.yearStartDate = yearStartDate;
        this.yearEndDate = yearStartDate.withMonth(12).plusDays(yearStartDate.withMonth(12).lengthOfMonth() -1);
        this.yearStartMonthInt = yearStartMonth;
        this.yearEndMonthInt = yearEndMonth;
    }

    @Override
    public String toString() {
        return "Year{" +
                "yearStartDate=" + yearStartDate +
                ", yearEndDate=" + yearEndDate +
                ", yearStartMonthInt=" + yearStartMonthInt +
                ", yearEndMonthInt=" + yearEndMonthInt +
                '}';
    }
}
